package com.shoulder.boot.system.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shoulder.boot.system.dto.DictQueryDTO;
import com.shoulder.boot.system.entity.Dict;
import com.shoulder.boot.system.vo.DictVo;
import com.shoulder.mybatis.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;

public class DictUtils implements PageUtils<Dict, DictVo> {

    public static DictUtils buildUtils() {
        return new DictUtils();
    }

    @Override
    public DictVo toVo(Dict entity) {
        DictVo vo = new DictVo();
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }
    public static LambdaQueryWrapper<Dict> buildQueryWrapper(DictQueryDTO queryDTO) {
        LambdaQueryWrapper<Dict> queryWrapper = new LambdaQueryWrapper<Dict>().orderByDesc(Dict::getCreateTime);
        queryWrapper.like(!ObjectUtils.isEmpty(queryDTO.getName()), Dict::getName, queryDTO.getName());
        queryWrapper.like(!ObjectUtils.isEmpty(queryDTO.getType()), Dict::getType, queryDTO.getType());
        queryWrapper.eq(!ObjectUtils.isEmpty(queryDTO.getStatus()), Dict::getStatus, queryDTO.getStatus());
        return queryWrapper;
    }
}